<html>
<head><meta charset="utf-8"><title>rustc vs llvm · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html">rustc vs llvm</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="184515687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184515687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184515687">(Dec 31 2019 at 00:15)</a>:</h4>
<p>Hey, I'm not sure whether it is right place to ask (I've seen that there's a wg-llvm channel but it's more of a discussion channel for a WG than a question one). So there it goes:</p>
<p>As far as I see, <code>rustc</code> uses <code>libLLVM</code> shared library as a compiler backend provider to compile to every target architecture allowed by LLVM. Thus, <code>x86-64-unknown-linux</code> allows me to (after downloading appropriate target <code>std</code> crate and so on via <code>rustup target add ...</code>) to compile for specific target. Where does this shared library live in <code>*-windows-*</code> toolchains? Both <code>msvc</code> and <code>gnu</code> toolchains have DLLs in <code>bin</code> directory for e.g. <code>rustc-drivers</code> (which I'd gladly love to learn what does it actually do) but there's no <code>libLLVM</code> library. It cannot be baked into <code>rustc</code> binary because it is too small. So where is it? Unless I got it wrong and it works completely in a different way.</p>



<a name="184590680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184590680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184590680">(Jan 01 2020 at 09:25)</a>:</h4>
<p>Hmm, maybe it's statically-linked into <code>.rustup/toolchains/nightly-x86_64-pc-windows-msvc/lib/rustlib/x86_64-pc-windows-msvc/codegen-backends/rustc_codegen_llvm-llvm.dll</code>?</p>



<a name="184590725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184590725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184590725">(Jan 01 2020 at 09:26)</a>:</h4>
<p>On a related note, why do I have both <code>toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-9-rust-1.41.0-nightly.so</code> and <code>toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libLLVM-9-rust-1.41.0-nightly.so</code>?</p>



<a name="184599755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184599755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184599755">(Jan 01 2020 at 14:06)</a>:</h4>
<p><span class="user-mention" data-user-id="203546">@Laurențiu Nicola</span> </p>
<blockquote>
<p>Hmm, maybe it's statically-linked into <code>rustc_codegen_llvm-llvm.dll</code></p>
</blockquote>
<p>That's possible. But firstly <code>rustc_codegen_llvm-llvm.dll</code> seems to be quite small in size - just 42 MB, where <code>libLLVM.so</code> weights almost 80 MB. Secondly, it is placed in a pretty weird directory - <code>.rustup/toolchains/&lt;toolchain&gt;/lib/rustlib/&lt;specific-target&gt;/codegen-backends/</code> where specific target is <code>x86_64-pc-windows-msvc</code>. If it was backend for generating code for all targets, then why is it placed in a host target directory?</p>
<blockquote>
<p>On a related note, why do I have both</p>
</blockquote>
<p>That's what I noticed as well. Duplication of libraries is only partial, though. Weird.</p>
<p>Is there some kind of document explaining internal architecture of toolchains and their dependencies?</p>



<a name="184599885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184599885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184599885">(Jan 01 2020 at 14:10)</a>:</h4>
<p>Static linking might explain the size. Re docs, I suppose the place to look into would be <a href="https://rust-lang.github.io/rustc-guide/codegen/backend-agnostic.html" target="_blank" title="https://rust-lang.github.io/rustc-guide/codegen/backend-agnostic.html">https://rust-lang.github.io/rustc-guide/codegen/backend-agnostic.html</a>, but it's not very helpful in this case. Maybe someone who's really familiar with how codegen works will chime in.</p>



<a name="184600361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184600361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184600361">(Jan 01 2020 at 14:26)</a>:</h4>
<p>Thanks for link. I agree that someone actively developing those bits would be invaluable.</p>



<a name="184608066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184608066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184608066">(Jan 01 2020 at 18:25)</a>:</h4>
<p><span class="user-mention" data-user-id="256068">@Gabriel Górski</span> Since LLVM is statically linked, the linker can eliminate a lot of unused code from the final binary. On the other hand <a href="http://libLLVM.so" target="_blank" title="http://libLLVM.so">libLLVM.so</a> needs to export the full LLVM API.</p>



<a name="184608859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184608859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184608859">(Jan 01 2020 at 18:48)</a>:</h4>
<p>That makes sense. So is in fact <code>LLVM</code> statically linked into <code>rustc_codegen_llvm-llvm.dll</code>? Why does linux toolchain differ so much from msvc one? Doesn't it make further maintaining of toolchains a bit harder? I mean I suppose there's valid reasoning behind decisions made or at least I have no expertise to decide there isn't. </p>
<p>Still, it would be really cool to know what are the exact responsibilities of included libraries/files and reasoning behind file hierarchy within .rustup directories. Is <a href="https://rust-lang.github.io/rustc-guide/" target="_blank" title="https://rust-lang.github.io/rustc-guide/">https://rust-lang.github.io/rustc-guide/</a> enough to find out? (had no time yet to dig into it)</p>



<a name="184608877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184608877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184608877">(Jan 01 2020 at 18:49)</a>:</h4>
<p>to my knowledge rustc guide does not document the directory layout, no</p>



<a name="184608880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184608880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184608880">(Jan 01 2020 at 18:49)</a>:</h4>
<p>(indeed I'm not sure there's any documentation beyond people's heads, in this area)</p>



<a name="184609011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609011">(Jan 01 2020 at 18:52)</a>:</h4>
<p>Hmm I see. </p>
<blockquote>
<p>beyond people's heads</p>
</blockquote>
<p>I can imagine toolchains become a bit messy over time. I thought there's some kind of documented-ish convention :P</p>



<a name="184609083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609083">(Jan 01 2020 at 18:54)</a>:</h4>
<p>hm, not sure I follow</p>



<a name="184609095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609095">(Jan 01 2020 at 18:55)</a>:</h4>
<p>the layout of the rust distribution is pretty ad-hoc, but has remained relatively stable over time</p>



<a name="184609315"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609315" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gabriel Górski <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609315">(Jan 01 2020 at 19:01)</a>:</h4>
<p>I'm not insinuating anything. If it works, it works. I'm just exploring insides of the ecosystem, that's all. I'd like to learn more about it. Rustc guide seems like a good starting point I guess</p>



<a name="184609325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609325">(Jan 01 2020 at 19:01)</a>:</h4>
<p>Sure! I think documenting the layout (not to stabilize it, but just for rustc devs) would be great.</p>



<a name="184609369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184609369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184609369">(Jan 01 2020 at 19:02)</a>:</h4>
<p>Just no one has done so yet :)</p>



<a name="184625674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/rustc%20vs%20llvm/near/184625674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Santiago Pastorino <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/rustc.20vs.20llvm.html#184625674">(Jan 02 2020 at 03:36)</a>:</h4>
<blockquote>
<p>to my knowledge rustc guide does not document the directory layout, no</p>
</blockquote>
<p>I think it would be great to do so :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>